/*
 * @Author: your name
 * @Date: 2021-04-08 16:20:17
 * @LastEditTime: 2021-05-17 14:16:12
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /vite-project/vite.config.ts
 */
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import styleImport from 'vite-plugin-style-import';

const mockPlugin = require('vite-plugin-mockit');

function pathResolve(dir: string) {
    return resolve(process.cwd(), '.', dir);
}

// https://vitejs.dev/config/
export default defineConfig({
    resolve: {
        alias: [
            // {
            //     find: '@',
            //     replacement: resolve(__dirname, './src'),
            // },
            // {
            //     find: '#',
            //     replacement: resolve(__dirname, './types'),
            // },
            {
                find: /@\//,
                replacement: pathResolve('src') + '/',
            },
            // /#/xxxx => types/xxxx
            {
                find: /#\//,
                replacement: pathResolve('types') + '/',
            },
        ],
    },
    css: {
        preprocessorOptions: {
            less: {
                modifyVars: {
                    // 引入全局变量使用
                    hack: `true; @import (reference) "${resolve(
                        'src/design/config.less'
                    )}";`,
                },
                javascriptEnabled: true,
            },
        },
    },
    plugins: [
        vue(),
        mockPlugin({
            entry: './mock/index.js',
            watchFiles: [],
            watchOptions: {},
            ignore: /_test/,
        }),
        styleImport({
            libs: [
                {
                    libraryName: 'ant-design-vue',
                    esModule: true,
                    resolveStyle: (name) => {
                        return `ant-design-vue/es/${name}/style/index`;
                    },
                },
            ],
        }),
    ],
});
